# 作者: YYJ
# 2025年07月12日16时46分05秒
# 2486249622@qq.com
from collections.abc import Iterable, Iterator

class MyList(object):
    def __init__(self):
        self.container = []

    def add(self, item):
        self.container.append(item)

    def __iter__(self):
        """
        :return:可迭代对象
        """
        return MyIterator(self)

class MyIterator:
    def __init__(self, mylist):
        self.mylist = mylist
        self.current = 0

    def __next__(self):
        if self.current >= len(self.mylist.container):
            raise StopIteration
        current_value = self.mylist.container[self.current]
        self.current += 1
        return current_value

if __name__ == '__main__':
    my_list = MyList()
    # for i in my_list: # 此时my_list对象不是可迭代对象
    #     pass

    # print(isinstance(my_list, Iterable))    # True

    my_list.add(1)
    my_list.add(2)
    my_list.add(3)
    for i in my_list:
        print(i)